﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HYSoft.Web
{
    public partial class bianpo_manage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["uid"] == null || Session["uid"] == "")
            {
                Context.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
                Context.Response.Write("alert('对不起,你登录时间超时,请重新登录');top.location.href=\"index.html\";");
                Context.Response.Write("</script>");
                Context.Response.End();
            }
            if (!IsPostBack)
            {
                string type = Session["Usertype"] == null ? string.Empty : (string)Session["Usertype"];
                if (type != "单位用户")
                {
                    Response.Write("<script>alert('对不起，您没有管理边坡信息的权限！');history.go(-1);</script>");

                }
                else if (Request.QueryString["id"] == null || Request.QueryString["id"] == string.Empty)
                {
                    GetBPList();
                }
                else
                {
                    Delete();
                }
            }
        }
        //绑定数据
        protected void GetBPList()
        {
            try
            {
                string sql = " usr2monitor.[index]=tb_bpinfo.ljbp_sec_id and usr2monitor.user_index=" + Session["uid"].ToString() + "";
                DataSet ds = new BLL.usr2monitor().GetListfrom(sql);
                ListView1.DataSource = ds.Tables[0];
                ListView1.DataBind();
            }
            catch
            {
                Response.Redirect("errorpage.htm");
            }
        }
        //
        protected void Delete()
        {
            try
            {
                string id = Request.QueryString["id"];
                string sql = " ljbp_sec_id=" + id + " ";
                DataTable dt = new BLL.bpinfo().GetList(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    new BLL.bpinfo().Delete(int.Parse(dt.Rows[0]["bpid"].ToString()));
                }
                DataTable dt1 = new BLL.bp_jz().GetList(sql).Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int ljbp = int.Parse(dt1.Rows[0]["ljbp_sec_id"].ToString());
                    int mac = int.Parse(dt1.Rows[0]["mac"].ToString());
                    new BLL.bp_jz().Delete(ljbp, mac);
                }
                GetBPList();
            }
            catch
            {
                Response.Redirect("errorpage.htm");
            }
        }
    }
}